package cn.ffcs.uec.outStaffAdjustApply.action;

import java.text.ParseException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Components;
import org.zkoss.zk.ui.WrongValueException;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zk.ui.event.Events;
import org.zkoss.zk.ui.event.ForwardEvent;
import org.zkoss.zul.Messagebox;

import cn.ffcs.raptornuke.plugin.common.zk.ctrl.BasePortletComposer;
import cn.ffcs.raptornuke.plugin.common.zk.util.ZkUtil;
import cn.ffcs.raptornuke.portal.theme.ThemeDisplay;
import cn.ffcs.uec.common.manager.CustomFilesManager;
import cn.ffcs.uec.common.util.NodeVoUtil;
import cn.ffcs.uec.common.util.UecConstants;
import cn.ffcs.uec.common.vo.UecBdPsncl;
import cn.ffcs.uec.organization.manager.UecOrgDeptManager;
import cn.ffcs.uec.organization.manager.UecOrgOrgsManager;
import cn.ffcs.uec.organization.model.UecOrgDept;
import cn.ffcs.uec.organization.vo.OrganizationRelationVo;
import cn.ffcs.uec.outStaff.manager.UecOutStaffManager;
import cn.ffcs.uec.outStaff.model.UecOutStaffInfo;
import cn.ffcs.uec.outStaffAdjustApply.action.bean.OutStaffAdjustApprovalViewMainBean;
import cn.ffcs.uec.post.dao.UecPostDao;
import cn.ffcs.uec.post.manager.UecPostManager;
import cn.ffcs.uec.post.model.UecPost;
import cn.ffcs.uec.post.vo.BasePostVo;
import cn.ffcs.uec.recordsApproval.constant.ApprovalConstants;
import cn.ffcs.uec.recordsApproval.manager.ActRunTaskManager;
import cn.ffcs.uec.recordsApproval.util.ApprovalUtil;
import cn.ffcs.uec.staff.manager.UecPsnjobManager;
import cn.ffcs.uec.staff.model.UecPsnjob;
import cn.ffcs.uec.staffRecords.vo.AtiOaBaseObject;
import cn.ffcs.uom.common.model.DefaultDaoFactory;
import cn.ffcs.uom.common.util.ApplicationContextUtil;
import cn.ffcs.uom.common.util.DateUtil;
import cn.ffcs.uom.common.util.ListboxUtils;
import cn.ffcs.uom.common.util.PubUtil;
import cn.ffcs.uom.common.util.StrUtil;

/**
 * 外包人员调配审批弹框Composer
 * 
 * @author liuxiaodong
 *
 */
@Controller
@Scope("prototype")
public class OutStaffAdjustApprovalViewMainComposer extends BasePortletComposer {
	private static final long serialVersionUID = -7221741867597720126L;

	private OutStaffAdjustApprovalViewMainBean bean = new OutStaffAdjustApprovalViewMainBean();

	private UecPsnjobManager uecPsnjobManager = (UecPsnjobManager) ApplicationContextUtil
			.getBean("uecPsnjobManager");

	private UecOrgOrgsManager uecOrgOrgsManager = (UecOrgOrgsManager) ApplicationContextUtil
			.getBean("uecOrgOrgsManager");

	private UecOrgDeptManager uecOrgDeptManager = (UecOrgDeptManager) ApplicationContextUtil
			.getBean("uecOrgDeptManager");

	private UecPostManager uecPostManager = (UecPostManager) ApplicationContextUtil
			.getBean("uecPostManager");

	private UecOutStaffManager uecOutStaffManager = (UecOutStaffManager) ApplicationContextUtil
			.getBean("uecOutStaffManager");

	private ActRunTaskManager actRunTaskManager = (ActRunTaskManager) ApplicationContextUtil
			.getBean("actRunTaskManager");

	private CustomFilesManager customFilesManager = (CustomFilesManager) ApplicationContextUtil
			.getBean("customFilesManager");

	private UecPostDao uecPostDao = (UecPostDao) ApplicationContextUtil
			.getBean("uecPostDao");

	private String taskDefKey;

	private UecOutStaffInfo outStaffInfo = UecOutStaffInfo.newInstance();

	/**
	 * 人员试用
	 */
	private UecPsnjob psnjob = UecPsnjob.newInstance();

	// 部门第一负责人
	public static final String HEAD_OF_DEPARTMENT = "1001AA100000001ZIHCY";
	// 部门其他负责人
	public static final String OTHER_OF_DEPARTMENT = "1001AA100000001ZIHCZ";
	// 专业序列
	public static final String PROFESSIONAL_SEQ = "1001A1100000000006R3";
	// 管理序列
	public static final String MANAGERMENT_SEQ = "1001A1100000000006R2";

	/**
	 * 岗位
	 */
	private UecPost uecPost;
	/**
	 * 组织
	 */
	private UecOrgDept findUecOrgDept;

	/**
	 * 选择的组织
	 */
	private OrganizationRelationVo organization;

	/**
	 * 选择的基准岗位 三级
	 */
	private BasePostVo basePostVo;
	/**
	 * 二级基准岗
	 */
	private BasePostVo basePostVoB;
	/**
	 * 一级基准岗
	 */
	private BasePostVo basePostVoA;

	private String postSequence = null;

	private String basePostCodeA = null;

	private String basePostCodeB = null;

	private String basePostCodeC = null;
	// 基准岗位主键 == 三级基准岗位主键
	private String pkBasePostC = null;
	// 二级基准岗位主键
	private String pkBasePostB = null;
	// 一级基准岗位主键
	private String pkBasePostA = null;

	/**
	 * 人员类别
	 */
	private UecBdPsncl uecBdPsnclTree;

	private String opType;

	private String taskId;

	private AtiOaBaseObject oaBaseObject;

	@Override
	public String getPortletId() {
		return super.getPortletId();
	}

	@Override
	public ThemeDisplay getThemeDisplay() {
		return super.getThemeDisplay();
	}

	public void doAfterCompose(Component comp) throws Exception {
		super.doAfterCompose(comp);
		Components.wireVariables(comp, bean);

		this.bean.getUecPostBandboxExt().addForward("onUecPostEditSelected",
				comp, "onUecPostEditSelectedResponse");
		this.bean.getOutStaffPkDept().addForward("onGetOrganization", comp,
				"onGetOrganizationResponse");
		this.bean.getOutPsncl().addForward("onGetBdPsncl", comp,
				"onGetBdPsnclResponse");
	}

	/**
	 * 界面初始化
	 */
	public void onCreate$outStaffAdjustApprovalViewMainWin() {
		bandListbox();
		bindBean();
		bean.getUecPostBandboxExt().setDisabled(true);
	}

	/**
	 * 监听人员类别组织树
	 */
	public void onGetBdPsnclResponse(final ForwardEvent event) {
		if (event.getOrigin().getData() != null) {
			uecBdPsnclTree = (UecBdPsncl) event.getOrigin().getData();
		}
	}

	/**
	 * 监听--领导职务
	 */
	public void onSelect$jobglbdef25() {
		String pkPsdoc = (String) bean.getJobglbdef25().getSelectedItem()
				.getValue();
		/**
		 * 如果领导职务为：部门第一负责人或者部门其他负责人，负责部门取部门
		 */
		if (HEAD_OF_DEPARTMENT.equals(pkPsdoc)
				|| OTHER_OF_DEPARTMENT.equals(pkPsdoc)) {
			if (null != findUecOrgDept) {
				bean.getJobglbdef26().setValue(findUecOrgDept.getName());
			}
		} else {
			bean.getJobglbdef26().setValue(null);
		}
	}

	/**
	 * 监听组织树插件抛出的事件
	 * 
	 * @param event
	 */
	public void onGetOrganizationResponse(final ForwardEvent event) {
		if (event.getOrigin().getData() != null) {
			organization = (OrganizationRelationVo) event.getOrigin().getData();
			if ("ORG".equals(organization.getOrgType())) {
				ZkUtil.showError("调配后部门选项请选择到部门!", "错误提示");
				bean.getOutStaffPkDept().setValue(null);
				bean.getHrorg().setValue(null);
				bean.getUecPostBandboxExt().setValue(null);
				bean.getPkPostseries().setValue(null);
				bean.getJobglbdef22Name().setValue(null);
				bean.getJobglbdef23Name().setValue(null);
				bean.getJobglbdef24Name().setValue(null);
				bean.getUecPostBandboxExt().setDisabled(true);
				return;
			} else {
				bean.getUecPostBandboxExt().setDisabled(false);
				// 根据部门主键：pkorg，找到该部门所在的公司
				findUecOrgDept = new UecOrgDept();
				findUecOrgDept.setPkDept(organization.getOrg());
				findUecOrgDept = uecOrgDeptManager
						.findUecOrgDeptByOrgDept(findUecOrgDept);
				if (null != findUecOrgDept) {
					//
					bean.getHrorg().setValue(
							uecOrgOrgsManager
									.getUecOrgOrgsNameByPkOrg(findUecOrgDept
											.getPkOrg()));
					bean.getUecPostBandboxExt().setValue(null);
					Events.postEvent("onUecDeptSelect", this.bean
							.getUecPostBandboxExt().getBean()
							.getUecPostListboxExt(), findUecOrgDept);
				}
			}
		}
	}

	/**
	 * 监听基准岗位参考树
	 * 
	 * @param event
	 */
	public void onGetBasePostResponse(final ForwardEvent event) {
		if (event.getOrigin().getData() != null) {
			basePostVo = (BasePostVo) event.getOrigin().getData();
			if (!"3".equals(basePostVo.getLv())) {
				ZkUtil.showError("基准岗位请选择到最后一级!", "错误提示");
				bean.getOutStaffBasePost().setValue(null);
				bean.getJobglbdef23Name().setValue(null);
				bean.getJobglbdef22Name().setValue(null);
				return;
			}
			// 根据所选择的的第三级基准岗位，查出第二级、第一级基准岗位，并赋值
			// 获取第三级基准岗位编码
			// String codeC = basePostVo.getCode();
			// 获取第三级基准岗位的上级编码
			String preCodeC = basePostVo.getPcode();
			// 根据三级基准岗位获取二级基准岗位
			basePostVoB = uecPostDao.getPreviousBasePostByCode(preCodeC);
			if (basePostVoB != null) {
				bean.getJobglbdef23Name().setValue(basePostVoB.getPostname());
				// 根据二级基准岗位获取一级基准岗位
				basePostVoA = uecPostDao.getPreviousBasePostByCode(basePostVoB
						.getPcode());
				if (basePostVoA != null) {
					bean.getJobglbdef22Name().setValue(
							basePostVoA.getPostname());
				}
			}
		}
	}

	/**
	 * 监听UecOrgPostBandboxExt传出的事件
	 * 
	 * @param event
	 */
	public void onUecPostEditSelectedResponse(final ForwardEvent event) {
		if (event.getOrigin().getData() != null) {
			uecPost = (UecPost) event.getOrigin().getData();
			if (null != uecPost) {
				// 岗位--页面岗位赋值
				bean.getUecPostBandboxExt().setValue(uecPost.getPostname());
				// 岗位序列 --页面赋值
				postSequence = uecPost.getPkPostseries();
				if ("1001A1100000000006R2".equals(postSequence)) {
					bean.getPkPostseries().setValue("管理序列");
				} else if ("1001A1100000000006R3".equals(postSequence)) {
					bean.getPkPostseries().setValue("专业序列");
				}
				// 判断该岗位的基准岗位主键是否为空
				if (!StrUtil.isEmpty(uecPost.getPkPoststd())) {
					// 基准岗位主键 == 三级基准岗位主键
					pkBasePostC = uecPost.getPkPoststd();
					// 根据基准岗位主键查出基准岗位编码
					UecPost uecBasePostC = UecPost.newInstance();
					uecBasePostC.setPkPoststd(pkBasePostC);
					uecBasePostC = uecPostDao
							.queryBasePostByUecPost(uecBasePostC);
					if (uecBasePostC != null) {
						// 三级基准岗编码
						basePostCodeC = uecBasePostC.getPostcode();
						// 三级基准岗名称
						bean.getJobglbdef24Name().setValue(
								uecBasePostC.getPostname());
						// 获取二级基准岗位编码
						basePostCodeB = uecPostDao
								.getPreviousCodeByCode(basePostCodeC);
						if (!StrUtil.isNullOrEmpty(basePostCodeB)) {
							UecPost uecBasePostB = UecPost.newInstance();
							uecBasePostB = uecPostDao
									.getPkPostByCode(basePostCodeB);
							if (uecBasePostB != null) {
								// 二级基准岗位编码
								basePostCodeB = uecBasePostB.getPostcode();
								// 二级基准岗位主键
								pkBasePostB = uecBasePostB.getPkPost();
								// 二级基准岗名称
								bean.getJobglbdef23Name().setValue(
										uecBasePostB.getPostname());
								// 获取一级基准岗位编码
								basePostCodeA = uecPostDao
										.getPreviousCodeByCode(basePostCodeB);
								if (!StrUtil.isNullOrEmpty(basePostCodeA)) {
									UecPost uecBasePostA = UecPost
											.newInstance();
									uecBasePostA = uecPostDao
											.getPkPostByCode(basePostCodeA);
									if (uecBasePostA != null) {
										// 二级基准岗位编码
										basePostCodeA = uecBasePostA
												.getPostcode();
										// 二级基准岗位主键
										pkBasePostA = uecBasePostA.getPkPost();
										// 二级基准岗名称
										bean.getJobglbdef22Name().setValue(
												uecBasePostA.getPostname());
									}
								}
							}
						}
					}
				}
			}
		}
	}

	/**
	 * 重新申请
	 * 
	 * @throws InterruptedException
	 */
	public void onOk() throws InterruptedException {

		// 非查看历史工单
		if (!"onView".equals(opType)) {
			// 判断任务是否已被处理
			boolean isCompleted = ApprovalUtil.isTaskCompleted(oaBaseObject,
					taskId);
			if (isCompleted) {
				onCancel();
				Events.postEvent(ApprovalConstants.ON_REFRESH_QUERY_RESPONSE,
						this.self, null);
				ZkUtil.showError("任务不存在或已被处理完毕！", "错误提示");
				return;
			}
			// 字段校验
			String msg = this.checkUacStaffData();
			if (null != msg) {
				Messagebox.show(msg);
				return;
			}
			Messagebox.show("是否提交审批？", "输入确认提示", Messagebox.OK
					| Messagebox.CANCEL, Messagebox.QUESTION,
					new EventListener() {
						@Override
						public void onEvent(Event event) throws Exception {
							if (((Integer) event.getData()).intValue() == Messagebox.OK) {
								postApprovalData();
								onCancel();
							} else {
								return;
							}
						}
					});
		} else {
			this.onCancel();
		}

	}

	public void postApprovalData() throws InterruptedException {
		String currentName = ApprovalUtil.getCurrentName();
		if (StrUtil.isNullOrEmpty(currentName)) {
			ZkUtil.showError("当前登录用户已失效，请重新登录！", "错误提示");
			return;
		}
		PubUtil.fillPoFromEditorBean(psnjob, bean);

		if (null != findUecOrgDept) {
			// 更新outStaffInfo
			outStaffInfo.setPkHrorg(findUecOrgDept.getPkOrg());
			outStaffInfo.setModifier(currentName);
			outStaffInfo.setModifiedTime(DateUtil.getCurrenDate());
			DefaultDaoFactory.getDefaultDao().updateObject(outStaffInfo);

			psnjob.setPkOrg(findUecOrgDept.getPkOrg());
			psnjob.setPkHrorg(findUecOrgDept.getPkOrg());
			psnjob.setPkDept(findUecOrgDept.getPkDept());
		}
		// 岗位序列
		if (null != postSequence) {
			psnjob.setPkPostseries(postSequence);
		}
		// 岗位
		if (null != uecPost) {
			psnjob.setPkPost(uecPost.getPkPost());
		}
		if (pkBasePostC != null) {
			// 三级基准岗位
			psnjob.setJobglbdef24(pkBasePostC);
		}
		if (null != pkBasePostB) {
			// 二级基准岗
			psnjob.setJobglbdef23(pkBasePostB);
		}
		if (null != pkBasePostA) {
			// 一级基准岗
			psnjob.setJobglbdef22(pkBasePostA);
		}
		// 人员类别
		if (null != uecBdPsnclTree) {
			String pkpsncl = uecBdPsnclTree.getPkPsncl();
			psnjob.setPkPsncl(pkpsncl);
		}

		// 生效日期
		psnjob.setBegindate(DateUtil.dateToStr(bean.getEffectDate().getValue()));

		// 获取任本岗位层级时间
		psnjob.setJobglbdef8(DateUtil
				.dateToStr(bean.getJobglbdef8().getValue()));
		// 任现岗位层级时间
		psnjob.setJobglbdef14(DateUtil.dateToStr(bean.getJobglbdef14()
				.getValue()));
		// 是否小CEO
		int jobglbdef21 = bean.getPoststat().getSelectedIndex();
		if (0L == jobglbdef21) {
			psnjob.setJobglbdef21("N");
		} else if (1L == jobglbdef21) {
			psnjob.setJobglbdef21("Y");
		}
		// 负责部门
		/**
		 * 如果领导职务为：部门第一负责人或者部门其他负责人，负责部门取部门
		 */
		if (null != findUecOrgDept) {
			if (null != bean.getJobglbdef25().getSelectedItem()) {
				String jobGlbdef25 = (String) bean.getJobglbdef25()
						.getSelectedItem().getValue();
				if (HEAD_OF_DEPARTMENT.equals(jobGlbdef25)
						|| OTHER_OF_DEPARTMENT.equals(jobGlbdef25)) {
					psnjob.setJobglbdef26(findUecOrgDept.getPkDept());
				}
			}
		}

		// 是否在岗
		int poststat = bean.getPoststat().getSelectedIndex();
		if (0L == poststat) {
			psnjob.setPoststat("Y");
		} else {
			psnjob.setPoststat("N");
		}

		psnjob.setModifiedtime(DateUtil.getCurrenDate());
		psnjob.setModifier(currentName);
		DefaultDaoFactory.getDefaultDao().updateObject(psnjob);

		Events.postEvent("onOKResponse", this.self,
				ApprovalConstants.ON_OK_RESULT);

	}

	/**
	 * 审批同意
	 * 
	 * @throws InterruptedException
	 */
	public void onApproval() throws InterruptedException {
		Messagebox.show("是否提交审批？", "输入确认提示", Messagebox.OK | Messagebox.CANCEL,
				Messagebox.QUESTION, new EventListener() {
					@Override
					public void onEvent(Event event) throws Exception {
						if (((Integer) event.getData()).intValue() == Messagebox.OK) {
							approvalData();
						} else {
							return;
						}
					}
				});
	}

	public void approvalData() {
		Map<String, Object> map = new HashMap<String, Object>();
		String comment = this.getComment(taskDefKey);
		map.put("comment", comment);
		map.put("onApprovalResult", ApprovalConstants.ON_APPROVAL_RESULT);
		Events.postEvent("onApprovalResponse", this.self, map);
		this.onCancel();
	}

	/**
	 * 审批拒绝
	 */
	public void onReject() {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("comment", this.getComment(taskDefKey));
		map.put("onRejectResult", ApprovalConstants.ON_REJECT_RESULT);
		Events.postEvent("onRejectResponse", this.self, map);
		this.onCancel();
	}

	/**
	 * 取消
	 */
	public void onCancel() {
		this.bean.getOutStaffAdjustApprovalViewMainWin().onClose();
	}

	/**
	 * 获取传值
	 * 
	 * @throws ParseException
	 * @throws WrongValueException
	 */
	private void bindBean() {
		String procDefName = (String) arg.get("procDefName");
		this.bean.getOutStaffAdjustApprovalViewMainWin().setTitle(
				procDefName + "审批");

		oaBaseObject = (AtiOaBaseObject) arg.get("oaBaseObject");
		if (!StrUtil.isNullOrEmpty(oaBaseObject)) {
			// 获取审批意见
			PubUtil.fillBeanFromPo(oaBaseObject, bean);
		}
		opType = (String) arg.get("opType");
		if ("onView".equals(opType)) {
			// 查看历史工单
			setButtonValid(true, false, false);
			setTextValid(true, true, true);
		} else {

			taskDefKey = (String) arg.get("taskDefKey");
			if ("modify".equals(taskDefKey)) {
				setButtonValid(true, false, false);
				setTextValid(false, false, false);
			} else {
				setButtonValid(false, true, true);
			}
			if ("deptLeaderAudit".equals(taskDefKey)) {
				this.bean.getSecondText().setRows(2);
				this.setTextValid(true, false, false);
				bean.getSecondText().setValue(null);
			}
			if ("hrAudit".equals(taskDefKey)) {
				this.bean.getThirdText().setRows(2);
				this.setTextValid(false, true, false);
				bean.getThirdText().setValue(null);
			}
			if ("hrLeaderAudit".equals(taskDefKey)) {
				this.bean.getFourthText().setRows(2);
				this.setTextValid(false, false, true);
				bean.getFourthText().setValue(null);
			}
		}

		taskId = (String) arg.get("taskId");
		if (null != oaBaseObject) {
			List<Map<String, Object>> list = actRunTaskManager
					.getRuTasks(oaBaseObject.getProcInstId());
			if (null == list) {
				ZkUtil.showError("未知错误!", "错误信息");
				return;
			}
			if (list.size() == 0) {
				String outStaffIdTmp = oaBaseObject.getOutStaffId();
				oaBaseObject.setOutStaffId(oaBaseObject.getOutStaffIdHis());
				oaBaseObject.setOutStaffIdHis(outStaffIdTmp);

				String psnjobIdTmp = oaBaseObject.getPsnjobIdModify();
				oaBaseObject.setPsnjobIdModify(oaBaseObject.getPsnjobIdHis());
				oaBaseObject.setPsnjobIdHis(psnjobIdTmp);

			}

			String psnjobIdHis = oaBaseObject.getPsnjobIdHis();
			// 获取人员信息-历史
			if (!StrUtil.isNullOrEmpty(psnjobIdHis)) {
				psnjob.setPsnjobId(Long.parseLong(psnjobIdHis));
				psnjob = uecPsnjobManager.findUecPsnjobById(psnjob);
				if (null != psnjob) {
					outStaffInfo.setOutStaffId(psnjob.getStaffId());
					outStaffInfo = uecOutStaffManager
							.findUecOutStaffInfoByOutStaffId(outStaffInfo);
					bean.getPsnName().setValue(outStaffInfo.getPsnName());
					bean.getPsnCode().setValue(outStaffInfo.getPsnCode());

					if (!StrUtil.isNullOrEmpty(psnjob.getPkOrg())) {
						// 调配前信息
						// 组织
						bean.getOrgName().setValue(
								uecOrgOrgsManager
										.getUecOrgOrgsNameByPkOrg(psnjob
												.getPkOrg()));
						// 部门
						bean.getDeptName().setValue(
								uecOrgDeptManager
										.getUecOrgDeptNameByPkDept(psnjob
												.getPkDept()));
						// 岗位
						bean.getPostName().setValue(
								uecPostManager.getUecPostNameByPkPost(psnjob
										.getPkPost()));
						// 人员类别
						UecBdPsncl uecBdPsncl = new UecBdPsncl();
						uecBdPsncl.setPkPsncl(psnjob.getPkPsncl());
						uecBdPsncl = customFilesManager
								.findUecUecBdPsnclByUecBdPsncl(uecBdPsncl);
						if (!StrUtil.isNullOrEmpty(uecBdPsncl)) {
							bean.getPersonnelCategory().setValue(
									uecBdPsncl.getName());
						}
						// 岗位序列
						if (PROFESSIONAL_SEQ.equals(psnjob.getPkPostseries())) {
							bean.getPostSequence().setValue("专业序列");
						} else if (MANAGERMENT_SEQ.equals(psnjob
								.getPkPostseries())) {
							bean.getPostSequence().setValue("管理序列");
						} else {
							bean.getPostSequence().setValue(null);
						}

						// 岗位层级
						bean.getPostLevel().setValue(
								customFilesManager
										.findCustomFilesByPkdefdoc(psnjob
												.getJobglbdef2()));
						// 岗位等级
						bean.getPostGrade().setValue(
								customFilesManager
										.findCustomFilesByPkdefdoc(psnjob
												.getJobglbdef3()));
						// 一级基准岗位
						bean.getBasePostA().setValue(
								uecPostDao.getUecPostNameByPkBostPost(psnjob
										.getJobglbdef22()));
						// 二级基准岗位
						bean.getBasePostB().setValue(
								uecPostDao.getUecPostNameByPkBostPost(psnjob
										.getJobglbdef23()));
						// 三级基准岗位
						bean.getBasePostC().setValue(
								uecPostDao.getUecPostNameByPkBostPost(psnjob
										.getJobglbdef24()));
						// 任职方式
						bean.getAppointmentWay().setValue(
								customFilesManager
										.findCustomFilesByPkdefdoc(psnjob
												.getJobmode()));
						// 免职方式
						bean.getAppointmentWay().setValue(
								customFilesManager
										.findCustomFilesByPkdefdoc(psnjob
												.getDeposemode()));
						// 职务名称
						bean.getPositionName().setValue(psnjob.getJobglbdef4());
						// 是否在岗--POSTSTAT
						if ("Y".equals(psnjob.getPoststat())) {
							bean.getIsOnDuty().setValue("是");
						} else if ("N".equals(psnjob.getPoststat())) {
							bean.getIsOnDuty().setValue("否");
						} else {
							bean.getIsOnDuty().setValue(null);
						}
						// 任职原因
						bean.getAppointmentReason().setValue(
								psnjob.getJobglbdef5());
						// 任职文号
						bean.getAppointmentNumber().setValue(
								psnjob.getJobglbdef6());
						// 免职文号
						bean.getAppointmentNumber().setValue(
								psnjob.getJobglbdef7());
						// 任本岗位层级时间
						bean.getRenaultLevelTime().setValue(
								psnjob.getJobglbdef8());
						// 任现岗位层级时间
						bean.getRenaultGradeTime().setValue(
								psnjob.getJobglbdef14());
						// 进入本单位来源
						bean.getEnterUnitDate().setValue(
								customFilesManager
										.findCustomFilesByPkdefdoc(psnjob
												.getJobglbdef10()));
						// 是否小CEO
						if ("Y".equals(psnjob.getJobglbdef21())) {
							bean.getIsCEO().setValue("是");
						} else if ("N".equals(psnjob.getJobglbdef21())) {
							bean.getIsCEO().setValue("否");
						} else {
							bean.getIsCEO().setValue(null);
						}
						// 人员类别备注
						bean.getPersonnelCategoryMemo().setValue(
								psnjob.getJobglbdef13());
						// 领导职务名称
						bean.getLeadingPosition().setValue(
								customFilesManager
										.findCustomFilesByPkdefdoc(psnjob
												.getJobglbdef25()));
						// 负责部门
						bean.getResponsibleDepartment().setValue(
								uecOrgDeptManager
										.getUecOrgDeptNameByPkDept(psnjob
												.getJobglbdef26()));
					}
				}

			}

			// 获取审批中人员调配信息
			String psnjobId = oaBaseObject.getPsnjobIdAdd();
			if (!StrUtil.isNullOrEmpty(psnjobId)) {
				psnjob = UecPsnjob.newInstance();
				psnjob.setPsnjobId(Long.parseLong(psnjobId));
				psnjob = uecPsnjobManager.findUecPsnjobById(psnjob);
				if (null != psnjob) {
					PubUtil.fillBeanFromPo(psnjob, bean);

					// 岗位序列
					if (PROFESSIONAL_SEQ.equals(psnjob.getPkPostseries())) {
						bean.getPkPostseries().setValue("专业序列");
					} else if (MANAGERMENT_SEQ.equals(psnjob.getPkPostseries())) {
						bean.getPkPostseries().setValue("管理序列");
					} else {
						bean.getPkPostseries().setValue(null);
					}
					// 生效日期
					bean.getEffectDate().setValue(
							DateUtil.patternStrToDate(psnjob.getBegindate()));
					// 组织
					bean.getHrorg().setValue(
							uecOrgOrgsManager.getUecOrgOrgsNameByPkOrg(psnjob
									.getPkOrg()));
					// 部门
					bean.getOutStaffPkDept().setValue(
							uecOrgDeptManager.getUecOrgDeptNameByPkDept(psnjob
									.getPkDept()));
					// 岗位
					bean.getUecPostBandboxExt().setValue(
							uecPostManager.getUecPostNameByPkPost(psnjob
									.getPkPost()));
					// 一级基准岗位
					bean.getJobglbdef22Name().setValue(
							uecPostDao.getUecPostNameByPkBostPost(psnjob
									.getJobglbdef22()));
					// 二级基准岗位
					bean.getJobglbdef23Name().setValue(
							uecPostDao.getUecPostNameByPkBostPost(psnjob
									.getJobglbdef23()));
					// 三级基准岗位
					bean.getJobglbdef24Name().setValue(
							uecPostDao.getUecPostNameByPkBostPost(psnjob
									.getJobglbdef24()));
					// 是否在岗--POSTSTAT
					if ("Y".equals(psnjob.getPoststat())) {
						bean.getPoststat().setSelectedIndex(0);
					}
					if ("N".equals(psnjob.getPoststat())) {
						bean.getPoststat().setSelectedIndex(1);
					}
					// 人员类别
					UecBdPsncl BdPsncl = new UecBdPsncl();
					BdPsncl.setPkPsncl(psnjob.getPkPsncl());
					BdPsncl = customFilesManager
							.findUecUecBdPsnclByUecBdPsncl(BdPsncl);
					if (!StrUtil.isNullOrEmpty(BdPsncl)) {
						bean.getOutPsncl().setValue(BdPsncl.getName());
					}
					// 任现岗位层级时间
					bean.getJobglbdef8().setValue(
							DateUtil.patternStrToDate(psnjob.getJobglbdef8()));
					// 任现岗位层级时间
					bean.getJobglbdef14().setValue(
							DateUtil.patternStrToDate(psnjob.getJobglbdef14()));
					// 是否小CEO
					if ("N".equals(psnjob.getJobglbdef21())) {
						bean.getJobglbdef21().setSelectedIndex(0);
					}
					if ("Y".equals(psnjob.getJobglbdef21())) {
						bean.getJobglbdef21().setSelectedIndex(1);
					}
					// 负责部门
					String pkPsdoc = null;
					if (!StrUtil.isNullOrEmpty(bean.getJobglbdef25()
							.getSelectedItem())) {
						pkPsdoc = (String) bean.getJobglbdef25()
								.getSelectedItem().getValue();
					}
					if (HEAD_OF_DEPARTMENT.equals(pkPsdoc)
							|| OTHER_OF_DEPARTMENT.equals(pkPsdoc)) {
						bean.getJobglbdef26().setValue(
								bean.getOutStaffPkDept().getValue());
					} else {
						bean.getJobglbdef26().setValue(null);
					}

				}

			}
		}

	}

	/**
	 * 获取审批意见
	 * 
	 * @param taskDefKey
	 * @return
	 */
	private String getComment(String taskDefKey) {
		if ("deptLeaderAudit".equals(taskDefKey)) {
			return this.bean.getSecondText().getValue();
		}
		if ("hrAudit".equals(taskDefKey)) {
			return this.bean.getThirdText().getValue();
		}
		if ("hrLeaderAudit".equals(taskDefKey)) {
			return this.bean.getFourthText().getValue();
		}
		return null;
	}

	/**
	 * 设置按钮
	 * 
	 * @param canEdit
	 * @param canApproval
	 * @param canReject
	 */
	private void setButtonValid(boolean canEdit, boolean canApproval,
			boolean canReject) {
		this.bean.getOkBtn().setVisible(canEdit);
		this.bean.getOkBtn().setDisabled(!canEdit);

		this.bean.getApprovalBtn().setVisible(canApproval);
		this.bean.getApprovalBtn().setDisabled(!canApproval);

		this.bean.getRejectBtn().setVisible(canReject);
		this.bean.getRejectBtn().setDisabled(!canReject);

	}

	/**
	 * 设置审批意见栏
	 * 
	 * @param secondCanEdit
	 * @param thirdCanEdit
	 * @param fourthCanEdit
	 */
	private void setTextValid(boolean secondCanEdit, boolean thirdCanEdit,
			boolean fourthCanEdit) {
		this.bean.getSecondText().setDisabled(!secondCanEdit);
		this.bean.getThirdText().setDisabled(!thirdCanEdit);
		this.bean.getFourthText().setDisabled(!fourthCanEdit);
	}

	/**
	 * 检测填入的参数是否为空
	 */
	private String checkUacStaffData() {
		if (StrUtil.isNullOrEmpty(bean.getTrnsreason().getSelectedItem()
				.getValue())) {
			return "请选择调配原因";
		} else if (StrUtil.isNullOrEmpty(bean.getEffectDate().getValue())) {
			return "请选择生效日期";
		} else if (StrUtil.isNullOrEmpty(bean.getOutStaffPkDept().getValue())) {
			return "请选择调配后部门";
		} else if (StrUtil
				.isNullOrEmpty(bean.getUecPostBandboxExt().getValue())) {
			return "请选择调配后岗位";
		} else if (StrUtil.isNullOrEmpty(bean.getOutPsncl().getValue())) {
			return "请选择调配后人员类别";
		} else if (StrUtil.isNullOrEmpty(bean.getJobglbdef2().getSelectedItem()
				.getValue())) {
			return "请选择调配后岗位层级";
		} else if (StrUtil.isNullOrEmpty(bean.getJobglbdef3().getSelectedItem()
				.getValue())) {
			return "请选择调配后岗位等级";
		} else if (StrUtil.isNullOrEmpty(bean.getJobglbdef10()
				.getSelectedItem().getValue())) {
			return "请选择进入本单位来源";
		}
		return null;
	}

	/**
	 * 绑定Listbox
	 */
	public void bandListbox() {
		// 调配原因
		ListboxUtils.rendererForEdit(bean.getTrnsreason(),
				NodeVoUtil.getDictionaries(UecConstants.CHANGR_REASON));
		// 岗位层级--JOBGLBDEF2
		ListboxUtils.rendererForEdit(bean.getJobglbdef2(),
				NodeVoUtil.getDictionaries(UecConstants.POST_HIERARCHY));
		// 岗位等级--Jobglbdef3
		ListboxUtils.rendererForEdit(bean.getJobglbdef3(),
				NodeVoUtil.getDictionaries(UecConstants.POST_LEVEL));
		// 进入本单位来源jobglbdef10-
		ListboxUtils.rendererForEdit(bean.getJobglbdef10(),
				NodeVoUtil.getDictionaries(UecConstants.ASSCESS_SOURCE_UTIL));
		// 任职方式
		ListboxUtils.rendererForEdit(bean.getJobmode(),
				NodeVoUtil.getDictionaries(UecConstants.WAY_OF_TENURE));
		// 免职方式
		ListboxUtils.rendererForEdit(bean.getDeposemode(),
				NodeVoUtil.getDictionaries(UecConstants.WAY_OF_DISMISSAL));
		// 领导职务
		ListboxUtils.rendererForEdit(bean.getJobglbdef25(),
				NodeVoUtil.getDictionaries(UecConstants.LEADING_POSITION));
	}

}
